package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Provider;
import com.ruoyi.system.service.IProviderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供货商格Controller
 * 
 * @author ruoyi
 * @date 2024-03-11
 */
@RestController
@RequestMapping("/system/provider")
public class ProviderController extends BaseController
{
    @Autowired
    private IProviderService providerService;

    /**
     * 查询供货商格列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Provider provider)
    {
        startPage();
        List<Provider> list = providerService.selectProviderList(provider);
        return getDataTable(list);
    }

    /**
     * 导出供货商格列表
     */
    @Anonymous
    @Log(title = "供货商格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Provider provider)
    {
        List<Provider> list = providerService.selectProviderList(provider);
        ExcelUtil<Provider> util = new ExcelUtil<Provider>(Provider.class);
        util.exportExcel(response, list, "供货商格数据");
    }

    /**
     * 获取供货商格详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(providerService.selectProviderById(id));
    }

    /**
     * 新增供货商格
     */
    @Anonymous
    @Log(title = "供货商格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Provider provider)
    {
        return toAjax(providerService.insertProvider(provider));
    }

    /**
     * 修改供货商格
     */
    @Anonymous
    @Log(title = "供货商格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Provider provider)
    {
        return toAjax(providerService.updateProvider(provider));
    }

    /**
     * 删除供货商格
     */
    @Anonymous
    @Log(title = "供货商格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(providerService.deleteProviderByIds(ids));
    }
}
